<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改消息通知公告')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-messagenotice-edit" th:object="${messageNotice}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <input name="title" th:field="*{title}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">简介：</label>
                <div class="col-sm-8">
                    <textarea name="synopsis" class="form-control">[[*{synopsis}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <input id="details" name="details" type="hidden" th:field="*{details}">
                <label class="col-sm-3 control-label">详情：</label>
                <div class="col-sm-8">

                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <button id="edit" class="btn btn-primary btn-xs m-l-sm" onclick="editDetails()" type="button">编辑</button>
                            <button id="save" class="btn btn-primary  btn-xs" onclick="saveDetails()" type="button">保存</button>
                        </div>
                        <div class="ibox-content" id="eg">

                            <div class="click2edit wrapper">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">创建时间：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <div class="input-group date">-->
<!--                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
<!--                        <input name="created" th:value="${#dates.format(messageNotice.created, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->

            <div class="form-group">
                <label class="col-sm-3 control-label">类型：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('message_type')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="type" th:value="${dict.dictValue}" th:field="*{type}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否展示：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('message_show')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="isShow" th:value="${dict.dictValue}" th:field="*{isShow}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" th:field="*{sort}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script type="text/javascript">

        $(document).ready(function () {
            $('.summernote').summernote({
                lang: 'zh-CN'
            });
        });
        var content = $("#details").val();
        $('.click2edit').summernote('code', content);
        $('.click2edit').summernote('destroy');
        var editDetails = function () {
            $("#eg").addClass("no-padding");
            $('.click2edit').summernote({
                lang: 'zh-CN',
                focus: true
            });
        };
        var saveDetails = function () {
            $("#eg").removeClass("no-padding");
            var aHTML = $('.click2edit').summernote('code');
            $('.click2edit').summernote('destroy');
            $("#details").val(aHTML)
        };

        var prefix = ctx + "system/messagenotice";
        $("#form-messagenotice-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-messagenotice-edit').serialize());
            }
        }

        $("input[name='created']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        layui.use('upload', function() {
            var $ = layui.jquery
                , upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                , url: '/common/upload' //改成您自己的上传接口
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#img_header ").html("<img src='" + res.url + "' style='width:80px;height:80px;'>");
                    $("#mainUrl").val(res.url);

                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText1');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        })
    </script>
</body>
</html>